package cn.yunhe.insurance.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author 杨敏
 * @date 2018/10/22 12:00
 */
public class FileUploadUtil {
    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    public static String fileUpLoad(MultipartFile file) {

        String filePath = "/usr/uploadFiles/";

        String fileName = System.currentTimeMillis()+file.getOriginalFilename();
        if (file != null) {
            File dest = new File(filePath + File.separator + fileName);
            if (!dest.getParentFile().isDirectory()) {
                dest.getParentFile().mkdirs();
            }
            try {
                file.transferTo(dest);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return fileName;
    }
}
